/**
 *  Authors:
 *  Scott Renaud
 *  Kevin Carrington
 * 
 *   February 5 - 2012
 *   
 *  Team 4 - Iteration 1
 *  COMP 354 / Winter 2012
 *  
 *  =============================
 *  
 *  TaskManager.java
 *  
 *  This is the Main program.
 *  
 *  Asks the user for input file name (a list of tasks) and output file name
 *   (a list of persons with their associated tasks).
 *  
 *  Creates Task and Person objects to store information read 
 *  from the input file.
 *  
 *  Finally, it outputs a resulting Person file (also to the screen for clarity)
 *  with total hours and tasks assigned. 
 *  
 */

package taskManagmentSystem;

import java.util.Vector;
import java.util.Scanner;

public class TaskManager {
	
	public static void main(String[] args) 
	{
		// helper variables
		Scanner keybo = new Scanner(System.in);
		String inputFile, outputFile;
		Person tempPerson;
		Task tempTask;
		IO IOProcessor;
		Vector<Task> taskList;
		Vector<Person> personList;
		PersonHelper personHelper;
		
		
		// welcome message
		System.out.println("===========================================");
		System.out.println("Welcome to Team 4's Task Manager (Iteration 1)!");
		System.out.println("===========================================\n");
		System.out.println("Please enter the name of the file you wish to read your Tasks from:");
		System.out.print("(you can use the test file: \"Tasks.txt\")\n>");
		
		// store input filename
		inputFile = keybo.nextLine();
			
		System.out.print("\nNow, please enter the name of the file you wish to write your 'Person' information to:\n>");
		
		// store output filename
		outputFile = keybo.nextLine();
		
		IOProcessor = new IO(inputFile, outputFile);
		taskList = new Vector<Task>();
		personList = new Vector<Person>();
		personHelper = new PersonHelper();

		// Import from text file containing tasks
	    IOProcessor.processImport(taskList);

	    // Loop through task list to construct person list
	   	for (int i = 0; i < taskList.size(); i++)
	   	{
	   		tempTask = taskList.get(i);
	   		tempPerson = personHelper.personExists(tempTask.getPerson(), personList);
	   	
	   		if (tempPerson != null)
	   		{
	   			tempPerson.setTotalHours(tempTask.getDuration());
	   			tempPerson.setListOfTasks(tempTask.getTitle());
	   		}
	   		else
	   		{
	   			tempPerson = new Person(tempTask.getPerson());
	   			tempPerson.setTotalHours(tempTask.getDuration());
	   			tempPerson.setListOfTasks(tempTask.getTitle());
	   			
	   			personList.add(tempPerson);
	   		}
	   	}
	   	
	   	//Export the newly constructed Person list to a text file (found in IO.java)
	   	IOProcessor.processExport(personList);
	   	
	   	System.out.println("===========================================");
		System.out.println("Thank you for using our super Task Manager!");
		System.out.println("Have a good one!");
  
	}	
}
